package com.wdh.kjs.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.view.annotation.event.OnClick;
import com.wdh.kjs.MainActivity;
import com.wdh.kjs.R;

/**
 * Created by CQH on 2016/4/21.
 */
public class AccountDetailsActivity extends BaseTopActivity implements View.OnClickListener{
    private Button exitLogin;
    private LinearLayout tel;
    private ImageView portrait;
    private Intent intent;
    private TextView account_detail_name;
    private TextView account_detail_phoneNumber;
    private String nickName;
    private String phoneNumber;
    private String partyId;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_detail);
        initTopBar("账户详情");
        SharedPreferences share = getSharedPreferences("logininfo", MODE_PRIVATE);
        nickName = share.getString("nickName", "");
        phoneNumber = share.getString("phoneNumber", "");
        partyId = share.getString("loginToken", "");
        Log.i("msg",partyId);
        initview();
        loadData();
    }

    private void loadData() {
        int i = nickName.length();
        if (i == 1) {
            account_detail_name.setText(nickName);
        } else if (i == 2) {
            account_detail_name.setText(nickName.substring(0, 1) + "*");
        } else {
            account_detail_name.setText(nickName.substring(0, 1) + "*" + nickName.substring(2, nickName.length()));
        }
        account_detail_phoneNumber.setText(phoneNumber.substring(0, 3) + "****" + phoneNumber.substring(phoneNumber.length() - 4, phoneNumber.length()));
    }

    private void initview() {
        exitLogin = (Button) findViewById(R.id.exitLogin);
        portrait = (ImageView)findViewById(R.id.portrait);
        account_detail_name = (TextView)findViewById(R.id.account_detail_name);
        account_detail_phoneNumber = (TextView)findViewById(R.id.account_detail_phoneNumber);
        portrait.setOnClickListener(this);
        exitLogin.setOnClickListener(this);
    }
    public void onClick(View v){
        switch (v.getId()){
            case R.id.portrait:
                intent = new Intent(this, UploadPortraitActivity.class);
                startActivity(intent);
                break;
            case  R.id.exitLogin:

               SharedPreferences.Editor editor = getSharedPreferences("logininfo", MODE_PRIVATE).edit();
               editor.putString("loginToken","");
                editor.putString("nickName","");
                editor.putString("phoneNumber", "");
                editor.putString("levels", "");
                editor.putString("type", "");
               editor.commit();

                intent = new Intent();
                intent.putExtra("state", "1");
                intent.setClass(this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);


                break;
        }
    }
}
